<%@ Page Language="vb" AutoEventWireup="false" CodeFile="VendorSearch.aspx.vb" Inherits="VendorSearch" 
    title="Vendor Search"  MasterPageFile="~/site.master"%>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {

        });

        function RunSearch() {
            $("#grid1").jqGrid({
                datatype: 'local',
                width: 940,
                colNames: ['ID', 'Name', 'City', 'State'],
                colModel: [
               		{ name: 'ID', index: 'ID', hidden: true, width: 5 },
                    { name: 'Name', index: 'Name', align: 'left' },
               		{ name: 'City', index: 'City', width: 50, align: 'left' },
               		{ name: 'State', index: 'State', width: 25, align: 'left' }
               	],
                sortable: true,
                altRows: true,
                viewrecords: true,
                altclass: "ITrackerGridViewRowAlternate",
                onSelectRow: function (id) {
                    var rowData = $(this).getRowData(id);
                    var temp = rowData["ID"];
                    location.href = 'Vendor/' + temp;
                }

            });
            $("#grid1").clearGridData();
            getGridData();
        }
        function getGridData() {
            // a=desc
            $.ajax({
                type: "POST",
                url: "VendorSearch.aspx/GetDataForGrid",
                data: "{a: '" + $("#<%=txtVendorName.ClientID %>").val() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data, textStatus) {
                    if (textStatus == "success") {
                        for (var i = 0; i <= data.d.length - 1; i++)
                            $("#grid1").addRowData(i, data.d[i]);
                    }
                },
                error: function () {
                    alert("Error with AJAX callback");
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <h2><asp:label ID="lblPageHeader" runat="server" CssClass="PageHeader"></asp:label></h2>
    <table>
        <tr>
            <td><b>Name:</b>&nbsp;</td>
            <td><asp:TextBox  CssClass="ITrackerTextBox" ID="txtVendorName" runat="server"></asp:TextBox></td>
            <td><input type="button" value="Search" onclick="RunSearch();" /></td>
        </tr>
    </table>
    <br />
    <table id="grid1" class="ITrackerGridView"></table>
</asp:Content>
